package com.dopper.ws;

import com.dopper.ws.annotation.WebsocketMapping;
import io.netty.channel.Channel;

import java.util.List;
import java.util.Map;

/**
 * websocket消息处理
 * <p>
 * description: 请使用注解{@link WebsocketMapping}来定义ws的请求路径
 *
 * @author jincarry
 * @date 2019-7-10 10:50:01
 */
public interface Websocket {

    /**
     * 当链接打开时
     *
     * @param channel     channel
     * @param headers     http-headers
     * @param queryString url-params
     */
    void onOpen(Channel channel, Map<String, String> headers, Map<String, List<String>> queryString);

    /**
     * 当接受到文本消息时
     *
     * @param channel channel
     * @param content msg
     */
    void onMsg(Channel channel, String content);

    /**
     * 当接受到二进制数据时
     *
     * @param channel channel
     * @param bytes   msg
     */
    void onMsg(Channel channel, byte[] bytes);

    /**
     * 接收到ping消息时
     *
     * @param channel channel
     */
    void onPing(Channel channel);

    /**
     * 接收到pong消息时
     *
     * @param channel channel
     */
    void onPong(Channel channel);

    /**
     * 链接关闭时
     *
     * @param channel channel
     */
    void onClose(Channel channel);

    /**
     * 发生错误时
     *
     * @param channel   channel
     * @param throwable ex
     */
    void onError(Channel channel, Throwable throwable);
}
